package com.hd.controller;

import com.hd.controller.base.BaseController;
import com.hd.entity.WorkCc;
import com.hd.entity.enums.WorkccStatus;
import com.hd.service.WorkCcService;
import com.hd.util.StringUtils;
import com.hd.util.result.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RequestMapping("/workCc")
@Controller
public class WorkCcController extends BaseController {
    @Autowired
    private WorkCcService workCcService;

    @RequestMapping("/manager")
    public String index(){
        return "jsp/personaloffice/workCc/workCcList";
    }

    @ResponseBody
    @RequestMapping("/dataGrid")
    public Object selectDataGrid(WorkCc workCc, Date createTimeStart,Date createTimeEnd,
                                 int page, int rows){
        PageInfo info=new PageInfo(page,rows);
        Map<String,Object> condition=new HashMap<String,Object>();
        if(StringUtils.isNotNull(createTimeStart)){
            condition.put("createTimeStart",createTimeStart);
        }
        if(StringUtils.isNotNull(createTimeEnd)){
            condition.put("createTimeEnd",createTimeEnd);
        }
        info.setCondition(condition);
        workCcService.selectDataGrid(info,workCc);
        return info;
    }

    /**
     * 阅读
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/read/{id}")
    public Object read(@PathVariable("id") String id){
        WorkCc workCc=workCcService.get(id);
        if(workCc!=null){
            if(workCc.getReadTime()==null){
                workCcService.updateById(id, WorkccStatus.OFF.getStatus());
            }
            return renderSuccess();

        }
        return renderError();
    }
}

